﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using WebApplication1.Business;

namespace WebApplication1
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        public bool check()
        {
            bool flag = true;
            if (txtUser.Text.Trim().Length < 6)
            {
                lbuser.Text = "ID must be more than 6 char !";
                flag = false;
            }
            else 
            {
                lbuser.Text = "";
                flag = true;
            }
            if (txtPass.Text.Trim().Length < 6)
            {
                lbpass.Text = "Password must be more than 6 char !";
                flag = false;
            }
            else
            {
                lbpass.Text = "";
                flag = true;
            }
            //if (txtConfirmPass.Text.Length < 6)
            //{
            //    lbconfirmpass.Text = "Password must be more than 6 !";
            //    flag = false;
            //}
            //else
            //{
            //    lbconfirmpass.Text = "";
            //    flag = true;
            //}
            if (txtConfirmPass.Text.Trim().Length == 0)
            {
                lbconfirmpass.Text = "*";
                flag = false;
            }
            else
            {
                lbconfirmpass.Text = "";
                flag = true;
            }
            if (txtFName.Text.Trim().Length == 0)
            {
                lbfname.Text = "*";
                flag = false;
            }
            else
            {
                lbfname.Text = "";
                flag = true;
            }
            if (txtLName.Text.Trim().Length == 0)
            {
                lblname.Text = "*";
                flag = false;
            }
            else
            {
                lblname.Text = "";
                flag = true;
            }
            if (txtPhone.Text.Trim().Length < 7)
            {
                lbphone.Text = " Error phone number !";
                flag = false;
            }
            else
            {
                lbphone.Text = "";
                flag = true;
            }
            if (txtAddress.Text.Trim().Length == 0)
            {
                lbaddress.Text = "*";
                flag = false;
            }
            else
            {
                lbaddress.Text = "";
                flag = true;
            }
            if (txtEmail.Text.Trim().Length == 0)
            {
                lbemail.Text = "*";
                flag = false;
            }
            else
            {
                lbemail.Text = "";
                flag = true;
            }
            return flag;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            UserBusiness us = new UserBusiness();
            bool flag = us.CheckCreat(txtUser.Text);
            if (check())
            {
                if (flag)
                {
                    App.showMessage(this.Page, GetType(), "UserID existed !", false);
                }
                else
                {
                    string date = cbDate.SelectedItem.ToString() + "/" + cbMonth.SelectedItem.ToString() + "/" + cbYear.SelectedItem.ToString();
                    bool gend = true;
                    if (RadioButton2.Checked)
                    {
                        gend = false;
                    }
                    us.CreatAcc(txtUser.Text, App.Encrypt(txtPass.Text), txtFName.Text, txtLName.Text, date, gend, Int32.Parse(txtPhone.Text), txtAddress.Text, txtEmail.Text, false);
                    App.showMessage(this.Page, GetType(), "Create successful !", false);
                }
            }
                
            
            
        }
    }
}
